const Router = require('koa-router');
const router = new Router({ prefix: '/carts' });
// 验证是否登录
const { auth } = require('../middleware/auth.middleware');
const { validator } = require('../middleware/cart.middleware')
const { add, findAll, update, remove ,selectAll,unselectAll} = require('../controller/cart.controller');

// 添加购物车
router.post('/', auth, validator({ goods_id: 'number' }), add)

// 获取购物车
router.get('/', auth, findAll)

// 更新数据库
router.patch('/:id', auth, validator({
    number: { type: 'number', required: false },
    selected: { type: 'bool', required: false },
}), update)

// 删除购物车 
router.delete('/', auth, validator({ ids: "array" }), remove)


// 购物车全选
router.post('/selectAll',auth,selectAll)
router.post('/unselectAll',auth,unselectAll)

// 购物车全不选

module.exports = router